import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
import AddEditModal from '#cpt/temp/AddEditModal'
import TableControls from '#cpt/temp/TableControls'
// ===================================================================== global declare
const { $fn } = window
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedRows:[],
		// 搜索表单列表
		forms : [
			{ label: '项目名称',		name: 'item_name' },
			{ label: '物价代码',		name: 'price_code' },
			{ label: '类型',  		name: 'type', type:'select', nameStr:'name',data:[{name:'项目',value:'2'},{name:'病理',value:'3'}] },
		],
		// 提交表单列表
		formData : [
			{ label: '三甲价格',		name: 'hosp_price_ta', 		half:true,	required:true },
			{ label: '三乙价格',		name: 'hosp_price_tb', 		half:true,	required:true },
			{ label: '二甲价格',		name: 'hosp_price_sa', 		half:true,	required:true },
			{ label: '二乙价格',		name: 'hosp_price_sb', 		half:true,	required:true },
			{ label: '普通价格',		name: 'hosp_price', 		half:true,	required:true },
			// { label: '标准价格',		name: 'price', 				half:true },
			// { label: '结算价格',		name: 'settlement_price', 	half:true },
			// { label: '状态',			name: 'enabled', 			half:true, type: 'select', data:[{name:'启用',value:'1'},{name:'待启用',value:'0'}] }
		]
	}
	
	model = {}
	
	load = ({ uuid }) => {
		this.query = { qt_temp_id:uuid }
		this.fetch()
	}
	
	// 查询项目paging
	fetch = () => $fn.fetch.call(this,'qt-comp-item/index', { isIndex:true })
	
	// 关联表单
	cols = [
		{ title: '物价代码',				dataIndex: 'price_code', 				width:150 },
		{ title: '关联物价',				dataIndex: 'price_rel_codes', 			width:150 },
		{ title: '中文简称',				dataIndex: 'item_name_sort', 			width:150 },
		{ title: '项目名称',				dataIndex: 'item_name', 				width:200 },
		{ title: '英文简称',				dataIndex: 'item_name_en_sort', 		width:100 },
		{ title: '英文名称',				dataIndex: 'item_name_en', 				width:200 },
		{ title: '检测方法',				dataIndex: 'detection_method_name', 	width:100 },
		{ title: '三甲价格', 			dataIndex: 'hosp_price_ta', 			...$fn.table.num },
		{ title: '三乙价格', 			dataIndex: 'hosp_price_tb', 			...$fn.table.num },
		{ title: '二甲价格', 			dataIndex: 'hosp_price_sa', 			...$fn.table.num },
		{ title: '二乙价格', 			dataIndex: 'hosp_price_sb', 			...$fn.table.num },
		{ title: '普通价格', 			dataIndex: 'hosp_price', 				...$fn.table.num },
		// { title: '标准价格',				dataIndex: 'contract_price', 			...$fn.table.num },
		// { title: '结算价格',				dataIndex: 'price', 					...$fn.table.num },
		{ title: '助记码',				dataIndex: 'qt_item_code', 				...$fn.table.num },
		{ title: '备注',				dataIndex: 'remark', 					width:200 },
		// { title: '状态',				dataIndex: 'enabled', 					...$fn.table.status,  render: text => +text === 1 ? '启用' : '待启用' },
		TableControls.controls.call(this)		
	]
	// 表格操作按钮
	table_controls = (text,{ qt_temp_id, source_item_id, category, type, price_code }) => {
		// 增加 只有单一项目才能 修改价格 [2021-8-10 5:46:45 ?F10: PM?] --伍智睿
		return [
			category === '25001' || +type === 3 || price_code === '270500002' ?
			TableControls.edit.call(this, 'qt-comp-item/info', { qt_temp_id, source_item_id }, {
				select: this.getModalSelect,
				load: ({ uuid, comp_id, source_item_id, id, operator_id, qt_temp_id,  })=> {
					this.submit = { uuid, comp_id, source_item_id, id, operator_id, qt_temp_id }
				},
			}) : null,				// 编辑
		]
	}
	render(){
		return (
			<>
				{/* 搜索 */}
				{ SearchForm.call(this) }
				{/* 表格 */}
				{ Table.call(this,{ isIndex:true }) }
				{/* 编辑 */}
				{ AddEditModal.call(this,{ editApi:'qt-comp-item/edit',text:'编辑成功，请等待审核' }) }
			</>
		)
	}
}

export default Index